from peewee import *
import datetime
import os

# 当前文件所在路径的绝对路径
BASEDIR = os.path.abspath(os.path.dirname(__file__))
db_name = os.path.join(BASEDIR, '../../app.db')
db = SqliteDatabase(db_name)


class User(Model):
    """用户模型"""
    username = CharField()
    password = CharField()
    create_time = DateTimeField(default=datetime.datetime.now(), formats='%Y-%m-%d %H:%m:%s')
    update_time = DateTimeField(default=datetime.datetime.now(), formats='%Y-%m-%d %H:%m:%s')

    @property
    def dict(self):
        return {
            'username': self.username,
            'password': self.password,
            'create_time': self.create_time,
            'update_time': self.update_time
        }

    class Meta:
        database = db


db.connect()

if __name__ == '__main__':
    data = list(User.select().dicts())
    print(data)
    print(list(data))
